﻿using IdentityModel;
using IdentityServer4.Models;
using IdentityServer4.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;

namespace idpDemo.Services
{
    public class ProfileService : IProfileService
    {
        public async Task GetProfileDataAsync(ProfileDataRequestContext context)
        {
            try
            { 
                //depending on the scope accessing the user data.
                var claims = context.Subject.Claims.ToList();

                //set issued claims to return
                context.IssuedClaims = claims.ToList();

                await Task.Run(() => { });
            }
            catch (Exception ex)
            {
                //log your error
            }
        } 
        public async Task IsActiveAsync(IsActiveContext context)
        {
            context.IsActive = true;
        }

        /// <summary>
        /// 设置Claim信息
        /// </summary>
        /// <returns></returns>
        private async Task<List<Claim>> GetClaimsFromUserAsync( )
        {
             
            var claims = new List<Claim>()
            { 
            };

            List<string> permissions = new List<string>() { };
            permissions.Add("default_get");
            permissions.ForEach(x => claims.Add(new Claim("permissions", x)));

            return claims;
        }



    }
     
}
